﻿Imports System.Data.SqlClient

Public Class clsGratificaciones
    Private mintidGratificacion As Integer
    Private mintidEmpleado As Integer
    Private mstrDepartamento As String
    Private mstrtipo As String
    Private mdblMonto As Double
    Private mstrMotivo As String
    Private mstrUsuario As String
    Private mdatFecha As Date
    Private mstrNotificado As String
    Private mstrTipoHora As String


    Public Property idGratificacion() As Integer
        Get
            Return mintidGratificacion
        End Get
        Set(ByVal value As Integer)
            mintidGratificacion = value
        End Set
    End Property
    Public Property IdEmpleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property

    Public Property Departamento() As String
        Get
            Return mstrDepartamento
        End Get
        Set(ByVal value As String)
            mstrDepartamento = value
        End Set
    End Property
    Public Property Tipo() As String
        Get
            Return mstrtipo
        End Get
        Set(ByVal value As String)
            mstrtipo = value
        End Set
    End Property
    Public Property Monto() As Double
        Get
            Return mdblMonto

        End Get
        Set(ByVal value As Double)
            mdblMonto = value
        End Set
    End Property
    Public Property Motivo() As String
        Get
            Return mstrMotivo
        End Get
        Set(ByVal value As String)
            mstrMotivo = value
        End Set
    End Property
    Public Property Usuario() As String
        Get
            Return mstrUsuario
        End Get
        Set(ByVal value As String)
            mstrUsuario = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Notificado() As String
        Get
            Return mstrNotificado
        End Get
        Set(ByVal value As String)
            mstrNotificado = value
        End Set
    End Property
    Public Property TipoHora() As String
        Get
            Return mstrTipoHora
        End Get
        Set(ByVal value As String)
            mstrTipoHora = value
        End Set
    End Property
    Public Sub New()
        mintidGratificacion = 0
        mintidEmpleado = 0
        mstrtipo = ""
        mstrTipoHora = ""
        mstrDepartamento = ""
        mdatFecha = Now()
        mstrMotivo = ""
        mstrUsuario = ""
        mdblMonto = 0
        mstrNotificado = ""
    End Sub
   
    Public Sub Borrar()
        Call SetSqlCitra("Delete From Gratificacion Where IdEmpleado = " & IdEmpleado)

    End Sub
    Public Sub Buscar()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Gratificaciones " & _
        " WHERE idEmpleado=" & IdEmpleado

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            mintidGratificacion = rdBuscar("idGratificacion")
            mintidEmpleado = rdBuscar("IdEmpleado")
            mstrtipo = rdBuscar("tipo").ToString.Trim
            mstrDepartamento = rdBuscar("Departamento").ToString.Trim
            mdatFecha = rdBuscar("fecha")
            mstrMotivo = rdBuscar("motivo").ToString.Trim
            mstrUsuario = rdBuscar("usuario").ToString.Trim
            mdblMonto = rdBuscar("monto")
            mstrNotificado = rdBuscar("notificado").ToString.Trim
            mstrTipoHora = rdBuscar("TipoHora").ToString.Trim
        Else
            mintidGratificacion = 0
            mintidEmpleado = 0
            mstrtipo = ""
            mstrTipoHora = ""
            mstrDepartamento = ""
            mdatFecha = Now()
            mstrMotivo = ""
            mstrUsuario = ""
            mdblMonto = 0
            mstrNotificado = ""
        End If

        rdBuscar.Close()
        cnConn.Close()
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Gratificaciones (" & _
                            "IdGratificacion," & _
                            "IdEmpleado," & _
                            "Departamento," & _
                            "Tipo," & _
                            "Monto," & _
                            "Motivo," & _
                            "Usuario," & _
                            "Fecha," & _
                            "Notificado," & _
                            "TipoHora)" & _
                            "VALUES (" & _
                            "@IdGratificacion," & _
                            "@IdEmpleado," & _
                            "SUBSTRING(@Departamento,1,30)," & _
                            "SUBSTRING(@Tipo,1,15)," & _
                            "@Monto," & _
                            "SUBSTRING(@Motivo,1,200)," & _
                            "SUBSTRING(@Usuario,1,200)," & _
                            "@Fecha," & _
                            "SUBSTRING(@Notificado,1,10)," & _
                            "SUBSTRING(@TipoHora,1,10))"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdGratificacion", mintidGratificacion)
        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Departamento", mstrDepartamento)
        Command.Parameters.AddWithValue("Tipo", mstrtipo)
        Command.Parameters.AddWithValue("Monto", mdblMonto)
        Command.Parameters.AddWithValue("Motivo", mstrMotivo)
        Command.Parameters.AddWithValue("Usuario", mstrUsuario)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Notificado", mstrNotificado)
        Command.Parameters.AddWithValue("TipoHora", mstrTipoHora)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Gratificacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
